package com.zsh.demo.configure;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
//@Configuration
public class WebConfig implements WebMvcConfigurer {
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
////        registry.addMapping("/**")//与访问路径
////                .allowedOrigins("Http://localhost:8080",null)//请求来源
////                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")//方法
////                .allowCredentials(true)//允许携带
////                .maxAge(3600);//相应最大时间
//        registry.addMapping("/**")
//                .allowedOrigins("http://localhost:8080", null)
//                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
//                .maxAge(3600)
//                .allowCredentials(true);
//    }


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("http://localhost:8080", null)
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .maxAge(3600)
                .allowCredentials(true);
    }
}
